#include "asm/stx7200reg.h"
#include "../../../cpu/sh/init_ram.S"

/*
 * This is derived from STMicroelectronics gnu toolchain example:
 *   sh-superh-elf/examples/os21/romdynamic/memory_mb671.S
 */

/*
 * The poke table is a series of long words, in the format
 *
 *	opcode, address, operand, ...
 *
 * An opcode of 0 marks the table end
 */

/*
 * For compatibility with old poke table code, we define some of the
 * new names, to map onto the old names. Ultimately, the old poke table
 * code will be updated to the "new order", and we can just delete
 * the following mappings.
 */
#define POKE8(A, VAL)				POKE_CHAR(A, VAL)
#define POKE16(A, VAL)				POKE_SHORT(A, VAL)
#define POKE32(A, VAL)				POKE_LONG(A, VAL)
#define OR32(A, VAL)				OR_LONG(A, VAL)
#define UPDATE32(A, AND, OR)			UPDATE_LONG(A, AND, OR)
#define POKE_UPDATE32(A1, A2, AND, SHIFT, OR)	POKE_UPDATE_LONG(A1, A2, AND, SHIFT, OR)
#define WHILE_NE32(A, AND, VAL)			WHILE_NE(A, AND, VAL)
#define DELAY(VAL)				/* do nothing */


	.section .data.init, "a"

	.balign 32

__memory_setup_table:

	/*
	 * include the appropriate set of "GDB pokes", (usually) generated
	 * using the "romgen" utility, from a known good target-pack.
	 *
	 * This file may be regenerated by connecting your specific board
	 * to an STMC2 (note: currently it must be version 2) and then
	 * executing the following command (redirecting the output):
	 *
	 * host% romgen --target-connect --show-comment <stmc2>:cb103:st40
	 *
	 * Where "<stmc2>" should be replaced with the IP address
	 * (or the DNS name) of the STMC2 box.  Also the "cb103" should
	 * substituted if you have a custom target-pack connect command.
	 *
	 * Note: The connect command used with "romgen", should connect
	 * only in 29-bit mode - even if U-Boot will be built for 32-bit mode.
	 * That is, do not use the "seuc=1" (or similar) option with "romgen".
	 */
#include "cb103.romgen"

#ifdef CONFIG_SH_SE_MODE
	/*
	 * Note that we also manually need to move the LMI0 and LMI1 base addresses to
	 * their 32-bit SE mode locations as defined in the datasheet and change the
	 * 'upper bound addresses' (in row attribute registers) for the LMIs.
	 */
	UPDATE_LONG(STX7200_SYSCONF_SYS_CFG38, 0xFFFFFF00, 0x00000040)
	UPDATE_LONG(STX7200_SYSCONF_SYS_CFG39, 0xFFFFFF00, 0x00000080)
	POKE_LONG(ST40_LMI_SDRA0_0(0), 0x50001a00)
	POKE_LONG(ST40_LMI_SDRA1_0(0), 0x50001a00)
	POKE_LONG(ST40_LMI_SDRA0_0(1), 0x90001a00)
	POKE_LONG(ST40_LMI_SDRA1_0(1), 0x90001a00)
#endif	/* CONFIG_SH_SE_MODE */

	END_MARKER

__memory_setup_table_end:

	.end
